<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item><i class="el-icon-date"></i> 问题管理</el-breadcrumb-item>
        <el-breadcrumb-item>问题详情</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <el-form ref="form" :model="form" label-width="100px">

        <el-form-item label="问题内容">
          <el-input type="textarea"  readonly v-model="form.content"></el-input>
        </el-form-item>
        <el-form-item label="提问时间">
          <el-input v-model="form.strTime" readonly></el-input>
        </el-form-item>
        <el-form-item label="提问部门">
          <el-input v-model="form.deptName" readonly></el-input>
        </el-form-item>
        <el-form-item label="提问医生">
          <el-input v-model="form.doctorName" readonly></el-input>
        </el-form-item>


        
      </el-form>



      <!-- 屏蔽提示框 -->
      <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
        <div class="del-dialog-cnt">屏蔽后无法恢复，是否确定屏蔽？</div>
        <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteComment">确 定</el-button>
            </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
  import 'quill/dist/quill.core.css';
  import 'quill/dist/quill.snow.css';
  import 'quill/dist/quill.bubble.css';
  import { quillEditor } from 'vue-quill-editor';
  export default {
    data: function(){
      return {
        form: {
          hospital:JSON.parse(sessionStorage.getItem('userMap')).hospital,
          quid:sessionStorage.getItem("quest_id"),
          commentList:[],
          deptName:'',
          doctorName:'',
          strTime:'',
          id:'',
        },
        cur_page:1,
        delVisible:false,
        editorOption: {
          placeholder: '开始编辑'
        },

      }
    },
    components: {
      quillEditor
    },
    computed:{

    },
    mounted :function(){
      this.isCover();
    },
    methods: {
      onEditorChange({ editor, html, text }) {
        this.content = html;
      },
      submit(formName){
        this.update()
        //this.$message.success('提交成功！');
      },
      /**
       * 覆盖原来的数据，重新加载
       */
      isCover(){
        console.log(sessionStorage.getItem("quest_id"));
        this.queryById(sessionStorage.getItem("quest_id"));
      },
      queryById(id){
        var that = this;
        this.form.content = '';
        this.form.deptName = '';
        this.form.doctorName = '';
        that.form.strTime = '';
          this.form.commentList = [];
        this.HttpUtil.encryptGet(
          this,
          this.Global.URLPATH.QUEST_BYQURSTID,
          {
            hospital :JSON.parse(sessionStorage.getItem('userMap')).hospital,
            token:sessionStorage.getItem("token"),
            id:id,
            pageNum:that.cur_page
          },
          function (data) {  console.log(data);
            data = JSON.parse(data.data);

            that.form.content = data.content;
            that.form.deptName = JSON.parse(data.json).deptName;
            that.form.doctorName = JSON.parse(data.json).doctorName;
            that.form.strTime = data.strTime;
            that.commentHandle(data.commentList);
          },
          function (data) {//访问失败
            that.tableData = [];
            that.total = 1;
            //that.$message.success(data.msg);
          });
      },
      commentHandle(commentList){
        if(commentList == null || commentList == undefined){
          return;
        }
        for(var i in commentList){
          commentList[i].deptName = JSON.parse(commentList[i].json).deptName;
          commentList[i].doctorName = JSON.parse(commentList[i].json).doctorName;
        }
        this.form.commentList = commentList;


      },
      deleteHandle(id){
        this.delVisible = true;
        this.form.id = id;
      },
      deleteComment(){
        var that = this;
        this.HttpUtil.encryptPost(
          this,
          this.Global.URLPATH.COMMENT_UPDATE,
          {
            hospital :JSON.parse(sessionStorage.getItem('userMap')).hospital,
            token:sessionStorage.getItem("token"),
            id:this.form.id,
            status:0
          },
          function (data) {
            that.$message.success("禁用成功");
            that.delVisible=false;
            that.queryById(that.form.quid);
          },
          function (data) {//访问失败

            that.$message.error(data.msg);
          });
      },
    },
    // queryById(id){
    //   var that = this;
    //   this.HttpUtil.encryptGet(
    //     this,
    //     this.Global.URLPATH.QUEST_BYQURSTID,
    //     {
    //       hospital :JSON.parse(sessionStorage.getItem('userMap')).hospital,
    //       token:sessionStorage.getItem("token"),
    //       id:id,
    //       pageNum:that.cur_page
    //     },
    //     function (data) {
    //       data = JSON.parse(data.data);
    //       that.form.content = data.list[0].content;
    //       that.form.deptName = JSON.parse(data.list[0].json).deptName;
    //       that.form.doctorName = JSON.parse(data.list[0].json).doctorName;
    //       that.commentHandle(data.list[0].commentList);
    //     },
    //     function (data) {//访问失败
    //       that.tableData = [];
    //       that.total = 1;
    //       //that.$message.success(data.msg);
    //     });
    // },
    // commentHandle(commentList){
    //   if(commentList == null || commentList == undefined){
    //     return;
    //   }
    //   for(var i in commentList){
    //     commentList[i].deptName = JSON.parse(commentList[i].json).deptName;
    //     commentList[i].doctorName = JSON.parse(commentList[i].json).doctorName;
    //   }
    //   this.commentList = commentList;
    //
    //
    // },
    watch:{
      $route(newValue, oldValue){
        if(newValue.path == "/quest/detail"){
          this.isCover();
        }
      }
    }
  }
</script>
<style scoped>
  .editor-btn{
    margin-top: 20px;
  }
</style>
